package com.skyolder.milkbee.service;

import java.time.ZonedDateTime;
import java.util.List;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.skyolder.milkbee.domain.Follow;
import com.skyolder.milkbee.repository.FollowRepository;

@Service
@Transactional
public class FollowService {
	@SuppressWarnings("unused")
	private final Logger log = LoggerFactory.getLogger(FollowService.class);

	@Inject
	private FollowRepository followRepository;
	public boolean isFocus(Long me,Long he){
		List<Follow> list=followRepository.findByFromUserIdAndToUserId(me,he);
		if(list==null){
			return false;
		}
		if(list.size()<=0){
			return false;
		}
		return true;
	}
	public boolean isFan(Long me,Long he){
		List<Follow> list=followRepository.findByFromUserIdAndToUserId(he,me);
		if(list==null){
			return false;
		}
		if(list.size()<=0){
			return false;
		}
		return true;
	}
	public Follow save(Follow follow){
		follow.setCreatedAt(ZonedDateTime.now());
		return followRepository.save(follow);
	}
	public List<Follow> findFocus(Long me, Long he) {
		return followRepository.findByFromUserIdAndToUserId(me,he);
	}
	public List<Follow> findMyFocus(Long me) {
		return followRepository.findByFromUserId(me);
	}
	public void delete(Follow follow) {
		// TODO Auto-generated method stub
		followRepository.delete(follow);
	}
}
